﻿Imports BLL
Public Class UnidadeCAD
    Inherits System.Web.UI.Page
    Dim objbll As New UnidadeBLL
    Dim cod As Integer = 0
#Region "Eventos"
#Region "Botão Gravar"
    Protected Sub BGravar_Click(sender As Object, e As EventArgs) Handles BGravar.Click
        Try
            objbll = New UnidadeBLL(Val(TCodigo.Text), TDescricao.Text.Trim)
            If (objbll.InserirAlterar(Session("usu_nome"))) Then
                BGravar.Enabled = False
                LMSG.Text = "Gravado com Sucesso!"
                LMSG.Visible = True
            End If
        Catch ex As Exception
            LMSG.ForeColor = Drawing.Color.Red
            LMSG.Text = ex.Message
            LMSG.Visible = True
        End Try
    End Sub
#End Region

#Region "Load"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cod = 0
        If Not IsPostBack() Then
            If Not IsNothing(Request("id")) Then
                cod = Val(Request("id"))
                BGravar.Text = "Alterar"
                carrega()
            End If
        End If
    End Sub
#End Region
#End Region

#Region "Métodos"
    Public Sub carrega()
        objbll = New UnidadeBLL(Val(cod))
        TCodigo.Text = objbll.Codigo
        TDescricao.Text = objbll.Descricao
    End Sub
#End Region

End Class